package cn.edu.suda.android.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.suda.android.bean.VoteInfo;
import cn.edu.suda.android.bean.VoteInfoExample;
import cn.edu.suda.android.dao.VoteInfoMapper;
import cn.edu.suda.android.service.VoteInfoService;

@Service
public class VoteInfoServiceImpl implements VoteInfoService {

	private VoteInfo voteInfo;
	private VoteInfoExample voteInfoExample;

	@Autowired
	private VoteInfoMapper voteInfoDao;

	@Override
	public int insertVoteInfo(List<VoteInfo> voteInfos) {
		int i = 0;
		for (VoteInfo voteInfo : voteInfos) {
			if (voteInfoDao.insertSelective(voteInfo) == 1) {
				i++;
			}
		}
		return i;
	}

	@Override
	public List<VoteInfo> getVoteInfo(String model) {
		return voteInfoDao.selectByModel(model);
	}

	@Override
	public int updateVoteInfo(VoteInfo voteInfo) {
		return voteInfoDao.updateByPrimaryKeySelective(voteInfo);
	}

	@Override
	public List<VoteInfo> getVoteResult() {
		return voteInfoDao.selectResult();
	}

	@Override
	public int destroyVoteInfo(String model) {
		voteInfo = new VoteInfo();
		voteInfo.setViMark(0);
		voteInfoExample = new VoteInfoExample();
		voteInfoExample.createCriteria().andViModelEqualTo(model);
		return voteInfoDao.updateByExampleSelective(voteInfo, voteInfoExample);
	}

}
